package com.leoandroid.tool.toolsbox.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.leoandroid.tool.toolsbox.bean.CurrExchangeBean
import com.leoandroid.tool.toolsbox.largeread.R
import com.leoandroid.tool.toolsbox.largeread.databinding.AdapterCurrencyExchangeBinding

class CurrencyExchangeAdapter(val context:Context,val data:List<CurrExchangeBean.ExchangeBean>): RecyclerView.Adapter<CurrencyExchangeAdapter.Holder>() {

    inner class Holder(itemview: View):RecyclerView.ViewHolder(itemview){

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
        val infate = DataBindingUtil.inflate<AdapterCurrencyExchangeBinding>(
            LayoutInflater.from(context),
            R.layout.adapter_currency_exchange,
            parent,
            false
        )
        return Holder(infate.root)
    }

    override fun onBindViewHolder(holder: Holder, position: Int) {
        val dataBind:AdapterCurrencyExchangeBinding? = DataBindingUtil.getBinding<AdapterCurrencyExchangeBinding>(holder.itemView)
        dataBind?.apply {
            nameTv.text = "货币名称："+data[position].name
            fBuyPri.text = "现汇买入价："+data[position].fBuyPri
            mBuyPri.text = "现钞买入价: "+data[position].mBuyPri
            fSellPri.text = "现汇卖出价: "+data[position].fSellPri
            mSellPri.text = "现钞卖出价: "+data[position].mSellPri
            bankConversionPri.text = "银行折算价: "+data[position].bankConversionPri
            dateTv.text = "发布日期: "+data[position].date
            timeTv.text = "发布时间："+data[position].time
        }
    }

    override fun getItemCount(): Int {
        return data.size
    }
}